﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default : System.Web.UI.Page
{
    ZSql info = new ZSql();

    string code = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        Hidvalue.Value = "";
        lblIp.Text = Page.Request.UserHostAddress;//用户当前ＩＰ地址

     //   ImageLogin_Click(null, null);
        
    }
    protected void ImageLogin_Click(object sender, ImageClickEventArgs e)
    {
        string sName = string.Empty;
        string sPwd = string.Empty;
        //code = Session["verifyCodeName"].ToString();
        if (string.IsNullOrEmpty(Request.QueryString["user"]))
        {
        sName = this.txtUserName.Text.Trim();
        sPwd = this.txtPwd.Text.Trim();
        }
        else
        {
              sName = Gift.Security.DESEncrypt.Decrypt(Request.QueryString["user"]);
              sPwd = Gift.Security.DESEncrypt.Decrypt(Request.QueryString["pwd"]);
        }

        info.Open("select userid,username,roleid,deptid,realname,ip from userInfo where username = '" + Common.FormatParameter(sName) + "' and password = '" + Common.WebEncrypt(sPwd) + "'");

        if (info.NextRow())
        {

            HttpCookie user = new HttpCookie("user");//定义Cookie
            user["id"] = info["userid"].ToString();
            user["name"] = Server.UrlEncode(info["username"].ToString());
            user["realname"] = Server.UrlEncode(info["realname"].ToString());
            user["roleid"] = info["roleid"].ToString();
            user["deptid"] = info["deptid"].ToString();
            user["ip"] = info["ip"].ToString();
            Response.Cookies.Add(user);
            if(Hidvalue.Value=="")
            {
               
                string url = "index.aspx";
                Response.Redirect(url);
			    //打开新窗口,并关闭当前窗口,IE6,IE7通用
             //   ClientScript.RegisterStartupScript(this.GetType(), "start", "var win=window.open('" + url + "','','top=0,left=0,scrollbars=no,status=0,directory=0,location=no');var h = screen.availHeight;var w = screen.availWidth;win.resizeTo(w,h);window.opener=null;window.open('','_self');window.close();", true);

            }            
        }
        else
        {
            Hidvalue.Value = "用户名或密码错误";
            ClientScript.RegisterStartupScript(typeof(Page), "aa", "alert('用户名或密码错误')", true);

        }
        info.Close();        
    }
}
